package org.lex.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class IconCache {
	private static final String Path = "/lex/resources/images/";
	// =============================================================
	public static final String CLOSE_ICON = "close.png";
	public static final String NormalClose = "close.normal.png";
	public static final String PressedClose = "close.pressed.png";
	public static final String RolloverClose = "close.rollover.png";
	// ==============================================================
	public static final String Arrow = "arrow.png";
	public static final String Refresh = "refresh.png";
	public static final String GoUp = "up.png";
	public static final String Tree = "tree.png";
	public static final String Notify = "notify.png";
	// ===============================================
	private static final Class<IconCache> c;
	private static final Map<String, Icon> map;
	static {
		c = IconCache.class;
		map = new ConcurrentHashMap<String, Icon>(20);
	}

	public static Icon getIcon(String key) {
		Icon icon = null;
		if (false == map.containsKey(key)) {
			icon = new ImageIcon(c.getResource(Path + key));
			map.put(key, icon);
		} else {
			icon = map.get(key);
		}
		return icon;
	}

	private IconCache() {
	}
}
